package com.example.sportrecord;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import com.example.sportrecord.SQL.LinearAdapter;
import com.example.sportrecord.SQL.SQLOperation;
import com.example.sportrecord.SQL.User;

import java.util.ArrayList;
import java.util.List;

public class SportRecord extends AppCompatActivity {
    private Context context;
    RecyclerView recyclerView;
    TextView total_record;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sport_record);
        initView();
        context=SportRecord.this;
        ArrayList<User> list;
        SQLOperation sqlOperation=new SQLOperation(context);
        list = sqlOperation.initData();

        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        LinearAdapter linearAdapter=new LinearAdapter(context,list);
//        LinearLayoutManager manager = new LinearLayoutManager(context);
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        recyclerView.setLayoutManager(manager);
//        recyclerView.setAdapter(linearAdapter);
        recyclerView.setAdapter(linearAdapter);
        initData();

    }

    public void initView(){
        recyclerView = (RecyclerView)findViewById(R.id.recv1);
        total_record = (TextView)findViewById(R.id.total_record);
    }
    public void initData(){
        SQLOperation sqlOperation=new SQLOperation(context);
        int total = sqlOperation.searchTotalData();
        total_record.setText(String.valueOf(total));

    }
}
